package peer.player;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CanvasThread implements Runnable{
	Thread mainThread;
	int wid;
	Player player;
	Shell shell2;
	Display display2;
	boolean visual=true;
	boolean fullScr=false;
	CanvasThread ct;
	org.eclipse.swt.graphics.Rectangle rec=null;
	public static void main(String[] args){

	}

	CanvasThread(Player player){
		ct=this;
		this.player=player;
		mainThread=new Thread(this);
		mainThread.start();
	}
	
	synchronized int getWid(){
		return wid;
	}
	
	void fullScreen(final int x,final int y,final int width,final int height){
		new Thread(){
			public void run(){
				display2.syncExec(new Runnable(){
					public void run(){
						rec=shell2.getBounds();
						OS.SetWindowPos (shell2.handle, OS.HWND_TOP, x, y, width,height, SWT.NULL);
					}
				});
			}
		}.start();
		
	}
	
	void fullScreenEsc(){
		new Thread(){
			public void run(){
				display2.syncExec(new Runnable(){
					public void run(){
						shell2.setBounds(rec);
					}
				});
			}
		}.start();
		
	}
	
	void setShellCanvasBounds(final int x,final int y,final int width,final int height){
	       new Thread(){
				public void run(){
					display2.syncExec(new Runnable(){
						public void run(){
							if(shell2!=null){
								shell2.setBounds(x, y+20, width, height);
							}
						}
					});
				}
			}.start();
		
	}
	
	public void run(){
		synchronized(ct){
			display2=new Display();
	        shell2 = new Shell(SWT.NO_TRIM);
	        shell2.setBackground(new Color(display2, new RGB(0x10, 0x10, 0x10)));
	       wid=shell2.handle;
		}
		
       while(! shell2.isDisposed()) {
           if(! display2.readAndDispatch()){
        	   display2.sleep();
           }
       }
       display2.dispose();
	}
}
